﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.SqlClient;

namespace INSTA.BankApplication.DAL
{
    public class SqlServerDbAccessor : AbstractDbAccessor
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="AbstractDbAccessor" /> class.
        /// </summary>
        /// <param name="mapper">The mapper.</param>
        /// <param name="connectionString">The connection string.</param>
        internal SqlServerDbAccessor(DataMapper mapper, string connectionString) : base(mapper, connectionString)
        {
            // Instanciate the correct type of SQL generator..
            SqlGenerator = new SqlServerSqlGenerator(mapper);

        }

        /// <summary>
        /// Initializes the typed database objects.
        /// </summary>
        protected override void InitTypedDatabaseObjects()
        {
            Connection  = GetNewConnection();
            Command     = GetNewCommand();
            Adapter     = new SqlDataAdapter();
        }

        /// <summary>
        /// Gets a new connection.
        /// </summary>
        /// <returns>a new connection.</returns>
        protected override IDbConnection GetNewConnection()
        {
            return new SqlConnection();
        }

        /// <summary>
        /// Gets a new Command.
        /// </summary>
        /// <returns>a new Command.</returns>
        protected override IDbCommand GetNewCommand()
        {
            return new SqlCommand();
        }
    }
}
